<?php

Raise::load('core.datetime.RaiseDate');

class TestCoreRaiseDate extends RaiseTest {
    
    public static function testClass(){
        self::assertClassExists('RaiseDate');
    }
    
    public static function testCreate(){
        $date = new RaiseDate(1, 2, 3);
        self::assertStrictEqual($date->day(), 3);
        self::assertStrictEqual($date->month(), 2);
        self::assertStrictEqual($date->year(), 1);
    }
    
    public static function testChangeDay(){
        $date = new RaiseDate(1, 2, 28);
        $date->day($date->day() + 1);
        self::assertStrictEqual($date->day(), 1);
        self::assertStrictEqual($date->month(), 3);
        self::assertStrictEqual($date->year(), 1);
    }
    
    public static function testChangeDay2(){
        $date = new RaiseDate(1, 12, 31);
        $date->day($date->day() + 1);
        self::assertStrictEqual($date->day(), 1);
        self::assertStrictEqual($date->month(), 1);
        self::assertStrictEqual($date->year(), 2);
    }
    
    public static function testAdd(){
        $date1 = new RaiseDate(1, 12, 31);
        $ts = new RaiseTimeSpan();
        $ts->day(2);
        $date2 = $date1->add($ts);
        self::assertObjectClass($date2, 'RaiseDate');
        self::assertStrictEqual($date2->year(), 2);
        self::assertStrictEqual($date2->month(), 1);
        self::assertStrictEqual($date2->day(), 2);
    }
    
    public static function testSubtract(){
        $date1 = new RaiseDate(1, 12, 1);
        $ts = new RaiseTimeSpan();
        $ts->day(3);
        $date2 = $date1->subtract($ts);
        self::assertObjectClass($date2, 'RaiseDate');
        self::assertStrictEqual($date2->year(), 1);
        self::assertStrictEqual($date2->month(), 11);
        self::assertStrictEqual($date2->day(), 29);
    }
    
    public static function testSubtract2(){
        $date1 = new RaiseDate(3, 1, 2);
        $ts = new RaiseTimeSpan();
        $ts->day(3);
        $date2 = $date1->subtract($ts);
        self::assertObjectClass($date2, 'RaiseDate');
        self::assertStrictEqual($date2->year(), 2);
        self::assertStrictEqual($date2->month(), 12);
        self::assertStrictEqual($date2->day(), 30);
    }
    
}